package com.worldcup.controller.question;

import com.worldcup.common.CommonResult;
import com.worldcup.model.dto.question.QuestionUserAnswerDTO;
import com.worldcup.service.question.calculator.MatchResultTaskPool;
import com.worldcup.service.question.impl.QuestionUserAnswerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author duwan.zq
 * @date 2019/03/06
 */
@RestController
@RequestMapping("/api/java/question/answer")
public class QuestionAnswerController {

    private final static Logger logger= LoggerFactory.getLogger(QuestionAnswerController.class);

    @Autowired
    private QuestionUserAnswerService answerService;

    @Autowired
    private MatchResultTaskPool matchResultTaskPool;

    /** 提交问卷答案 **/
    @RequestMapping(value = "/submit", method = RequestMethod.POST)
    public CommonResult submitQuestionAnswer(@RequestBody QuestionUserAnswerDTO questionUserAnswerDTO){
        answerService.submit(questionUserAnswerDTO.getOpenid(), questionUserAnswerDTO.getAnswers());
        return CommonResult.buildSuccess();
    }

    @RequestMapping(value = "/test/cal")
    public CommonResult calResult(){
        matchResultTaskPool.runAllUserTAsk();
        return  CommonResult.buildSuccess();
    }
}
